/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */

package jdbcmanager.procedure;

import java.sql.DatabaseMetaData;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;

import jdbcmanager.dbtools.datatypes.*;

/**
 * Shows Stored Prodcedure Name, Type and Remarks.
 *
 * @author Francisco Morero Peyrona
 */
final class InfoPanel extends JPanel
{
   private JLabel       lblName    = new JLabel();
   private JTextField   txtName    = new JTextField();
   private JLabel       lblRem     = new JLabel();
   private JTextField   txtRem     = new JTextField();
   private JPanel       pnlType    = new JPanel();
   private JRadioButton radUnknown = new JRadioButton();
   private JRadioButton radYes     = new JRadioButton();
   private JRadioButton radNo      = new JRadioButton();

   //-------------------------------------------------------------------------//
   
   public InfoPanel( StoredProcedureDefinition sp )
   {
      init();

      txtName.setText( sp.getName() );
      txtRem.setText( sp.getRemarks() );

      switch( sp.getTypeAsInt() )
      {
         case DatabaseMetaData.procedureNoResult:
            radNo.setSelected( true );
            break;

         case DatabaseMetaData.procedureReturnsResult:
            radYes.setSelected( true );
            break;

         case DatabaseMetaData.procedureResultUnknown:
         default:
            radUnknown.setSelected( true );
            break;
      }
   }

   private void init()
   {
      lblName.setText( "Name" );
      txtName.setEditable( false );

      lblRem.setText( "Remarks" );
      txtRem.setEditable( false );

      radUnknown.setText( "May return a ResultSet" );
      radUnknown.setEnabled( false );
      radYes.setText( "Do not return a ResultSet" );
      radYes.setEnabled( false );
      radNo.setText( "Return a ResultSet" );
      radNo.setEnabled( false );

      pnlType.setBorder( new TitledBorder( BorderFactory.createLineBorder( SystemColor.controlText, 1 ), " Return type " ) );
      pnlType.setLayout( new GridLayout( 3,1,0,0 ));
      pnlType.add( radYes );
      pnlType.add( radNo );
      pnlType.add( radUnknown );

      setLayout( new GridBagLayout() );
      
      add( lblName,  
           new GridBagConstraints(0,0,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(9,12,0,12), 0,0) );
      add( txtName,
           new GridBagConstraints(1,0,1,1,1.0,0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(9,0,0,12), 0,0) );
      
      add( pnlType,
           new GridBagConstraints(0,1,2,1,1.0,1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16,11,20,13), 0,0) );

      add( lblRem,
           new GridBagConstraints(0,2,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,12,9,12), 0,0) );
      add( txtRem,
           new GridBagConstraints(1,2,1,1,1.0,1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,9,12), 0,0) );
   }
}